$(function(){
	var caledarVal;
	calendar();
	$(".date_main").on("click","li",function(){
		$(".date_main").addClass("none");
	})
	/*---calendar select---*/
	$(".date_box").on("click","li",function(){
		caledarVal = $(this).attr("time");
		console.log(caledarVal)
		$(".a-select-date").text(caledarVal)
		if(!$(this).hasClass("unselect")){
			$(".month_date").children(".select").removeClass("select")
			$(this).addClass("select");
		}
	})
	$(".month_date li").click(function(){
		if(!$(this).hasClass("unselect")){
			$(".a-select-date").text($(this).attr("time"))
		}
	})
})
function calendar(date){
	var aDate = new Date();
	date = date || (aDate.getFullYear()+"-"+(aDate.getMonth()+1)+"-"+aDate.getDate());
	var arr = date.split('-');
	showDate(arr[0],arr[1],4)
}

//年月写入日历  !!!
    function showDate(yyyy,mm,monthsize){
        var daysCount;    
		monthsize = monthsize || 2;
        //本月
        var tyear= new Date().getFullYear();
        var tmonth = new Date().getMonth()+1;
		var tday = new Date().getDate();
        var titleHtml = " ",Datebox = $(".date_box");
        for( i = 0 ;i < monthsize;i++){
			var newDate =new Date(parseInt(yyyy),parseInt(mm)+i,0);
			var nowDate = newDate.getDate();
			var nowMonth = newDate.getMonth()+1;
			var nowYear = newDate.getFullYear();
			var week = new Date(Date.UTC(parseInt(yyyy),(parseInt(mm)+i)-1, 1)).getDay();;
			var mystr ="",setcolor = " ",unable = " ";
			daysCount = nowDate;
			for(k=0;k<daysCount;k++){
				var dayweek = new Date(Date.UTC(parseInt(yyyy),(parseInt(mm)+i)-1, k+1)).getDay()
            //计算格子
				if( k%7 == 0){
					if(k<7){
						for(j=0;j<week;j++){
							mystr += "<li class='unselect'></li>";
						}
					}
				}
				if(dayweek== 0 || dayweek == 6){
					setcolor = "week"
				}else{
					setcolor = "";
				}
				
				if(tyear == nowYear && tmonth == nowMonth && tday >= k+1){
					unable = "unselect";
					setcolor = "";
				}else{
					unable = " ";
				}
				if(tyear == nowYear && tmonth == nowMonth && tday == k+1){
					mystr += "<li  class='"+unable+" '><label></label><label class='"+setcolor+" Month_day'>今天</label><label class='Month_money'> </label></li>"; 
				}else{
					//这里一天，修改价格 填充内容在此
					mystr += "<li  class='"+unable+"' time ='"+nowYear+"-"+nowMonth+"-"+(k+1)+"'><label></label><label class='"+setcolor+" Month_day'>"+(k+1)+"</label><label class='Month_money'> </label></li>";
				}
			}
			//这里一个月的内容
			titleHtml = titleHtml+'<div  class="date_time" >'
								+'<div class="month">'+ nowYear+"年"+nowMonth+"月"+'</div>'
								+'<ul class="month_date">'+mystr+'</ul>'
								+'</div>'
		}
        Datebox.html(titleHtml);
}